home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUTORC.ZIP / TUT5.C < prev    next >
C/C++ Source or Header  |  1994-10-31  |  5KB  |  169 lines

  1. /*
  2.   tut5.c
  3.   10/30/94
  4.   from tutprog5.pas
  5.   Adapted from Denthor's tutprog5.pas
  6.   Translated into C, from Denthor's VGA Trainer, by
  7.   Steve Pinault, scp@ohm.att.com
  8.   Compiled with Microsoft Visual C++ 1.5 (Microsoft C 8.0)
  9.   To compile:
  10.   First compile the subroutines in tutsubs.c with the batch file 
  11.   cltutsub.bat
  12.   Then compile any of the tutor programs with the batch file
  13.   cltut.bat
  14.   Example: C:>cltutsub
  15.            C:>cltut tut5.c
  16.            to compile this program.
  17. */
  18.  
  19. #include "tutheadr.h"
  20.  
  21. #define xsize 16
  22. #define ysize 16
  23.  
  24. char Letter[xsize][ysize];
  25. char LetterBlock[62][xsize][ysize];
  26. char* Font;
  27.  
  28. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  29. // procedure LoadPal (FileName : string);
  30. // This loads the Pallette file and puts it on screen }
  31. int LoadPal(char* fn)
  32. {
  33.   struct DACType
  34.   {
  35.     char R;
  36.     char G;
  37.     char B;
  38.   } DAC[256];
  39.   FILE* fptr;
  40.   int i;
  41.  
  42.   if((fptr=fopen(fn,"rb"))==NULL)
  43.     { SetText(); printf("Error opening file %s\n",fn); exit(1); }
  44.   fread(DAC,sizeof(struct DACType),256,fptr);
  45.   fclose(fptr);
  46.   for(i=0;i<256;i++)Pal((char)i,DAC[i].R,DAC[i].G,DAC[i].B);
  47.   return 0;
  48. }
  49.  
  50. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  51. // Procedure Setup;
  52. //   { This loads the font and the pallette }
  53. void Setup()
  54. {
  55.     char fn[80];
  56.     char loop1;
  57.     int loop2,loop3;
  58.     FILE* fptr;
  59.     Font = &LetterBlock[0][0][0];
  60.   sprintf(fn,"%s","softrock.fnt");
  61.   if((fptr=fopen(fn,"rb"))!=NULL)
  62.   {
  63.     fread(Font,sizeof(LetterBlock),1,fptr);
  64.     fclose(fptr);
  65.   }
  66.   else
  67.   {
  68.     printf("SoftRock.FNT from TEXTER5 not found in current directory\n");
  69.     for(loop1=0;loop1<62;loop1++)
  70.       for(loop2=0;loop2<16;loop2++)
  71.         for(loop3=0;loop3<16;loop3++)
  72.           LetterBlock[loop1][loop2][loop3]=loop2;
  73.   }
  74.   SetMCGA();
  75.   LoadPal("pallette.col");
  76. }
  77.  
  78. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  79. // Procedure ScrollMsg (Msg : String);
  80. // This scrolls the string in MSG across the screen }
  81. void ScrollMsg(char* Msg)
  82. {
  83.   int loop1,loop2,loop3;
  84.   int index;
  85.   char MsgChar;
  86.   char far* Scrdest;
  87.   char far* Scrsrc;
  88.  
  89.   loop1=0;
  90.   while((MsgChar=Msg[loop1])!=0x00)
  91.   {
  92.     for(loop2=0;loop2<xsize;loop2++)
  93.     {
  94.     //This bit scrolls the screen by one then puts in the new row of letters 
  95.       WaitRetrace();
  96.       for(loop3=100;loop3<100+ysize;loop3++)
  97.       {
  98.         Scrdest=MK_FP(VGA,(unsigned)(loop3*320));
  99.         Scrsrc=MK_FP(VGA,(unsigned)(1+loop3*320));
  100.         _fmemmove(Scrdest,Scrsrc,319);
  101.       }
  102.       for(loop3=100;loop3<100+ysize;loop3++)
  103.       {
  104.         index=Msg[loop1]-32;
  105.         PutPixel(319,loop3,LetterBlock[index][loop2][loop3-100],VGA);
  106.       }
  107.       //    Change the -100 above to the minimum of loop3-1, which you
  108.       //    will change in order to move the position of the scrolly 
  109.     }
  110.  
  111.     //This next bit scrolls by one pixel after each letter so that there
  112.     //are gaps between the letters 
  113.  
  114.       WaitRetrace();
  115.       for(loop3=100;loop3<100+ysize;loop3++)
  116.       {
  117.         Scrdest=MK_FP(VGA,(unsigned)(loop3*320));
  118.         Scrsrc=MK_FP(VGA,(unsigned)(1+loop3*320));
  119.         _fmemmove(Scrdest,Scrsrc,319);
  120.       }
  121.       for(loop3=100;loop3<100+ysize;loop3++)
  122.       {
  123.         PutPixel(319,loop3,0,VGA);
  124.       }
  125.       loop1++;
  126.   }
  127. }
  128.  
  129.  
  130. void main()
  131. {
  132.   int c;
  133.   _clearscreen(_GCLEARSCREEN);
  134. /*
  135.   Writeln ('This program will give you an example of a scrolly. If the file');
  136.   Writeln ('SOFTROCK.FNT is in the current directory, this program will scroll');
  137.   Writeln ('letters, otherwise it will only scroll bars. It also searches for');
  138.   Writeln ('PALLETTE.COL, which it uses for it''s pallette. Both SOFTROCK.FNT');
  139.   Writeln ('and PALLETTE.COL come with TEXTER5.ZIP, at a BBS near you.');
  140.   Writeln;
  141.   Writeln ('You will note that you can change what the scrolly says merely by');
  142.   Writeln ('changing the string in the program.');
  143.   Writeln;
  144. */
  145.   Setup();
  146.   while(1)
  147.   {
  148.     ScrollMsg ("ASPHYXIA RULZ!!!   ");
  149.     c=_bios_keybrd(_KEYBRD_READY);
  150.     if(c)break;
  151.   }
  152.   SetText();
  153. /*
  154.   freemem (font, sizeof (font^));
  155.   Writeln ('All done. This concludes the fifth sample program in the ASPHYXIA');
  156.   Writeln ('Training series. You may reach DENTHOR under the name of GRANT');
  157.   Writeln ('SMITH on the MailBox BBS, or leave a message to ASPHYXIA on the');
  158.   Writeln ('ASPHYXIA BBS. Get the numbers from Roblist, or write to :');
  159.   Writeln ('             Grant Smith');
  160.   Writeln ('             P.O. Box 270');
  161.   Writeln ('             Kloof');
  162.   Writeln ('             3640');
  163.   Writeln ('I hope to hear from you soon!');
  164.   Writeln; Writeln;
  165.   Write   ('Hit any key to exit ...');
  166.   Readkey;
  167. */
  168.